package com.iteaj.network.test.server.line;

import com.iteaj.network.server.ServerProtocolHandle;
import com.iteaj.network.test.TestConst;
import com.iteaj.network.test.message.line.LineMessage;
import com.iteaj.network.test.message.line.LineMessageHead;
import com.iteaj.network.test.server.line.protocol.LineClientInitiativeProtocol;
import com.iteaj.network.test.server.line.protocol.LineServerInitiativeProtocol;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class ServerLineBasedHandle implements ServerProtocolHandle<LineClientInitiativeProtocol> {


    private Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private TestLineBasedFrameDecoderComponent component;

    @Override
    public Object handle(LineClientInitiativeProtocol initiativeProtocol) {
        LineMessage lineMessage = initiativeProtocol.requestMessage();
        LineMessageHead head = lineMessage.getHead();

        new LineServerInitiativeProtocol(head.getEquipCode()).request(protocol -> {
            String messageId = protocol.requestMessage().getHead().getMessageId();
            logger.info(TestConst.LOGGER_PROTOCOL_DESC, component.getName(), "服务端换行符测试",
                    head.getEquipCode(), messageId, protocol.getExecStatus().desc);

            return null;
        });

        return null;
    }
}
